package com.xizi;

import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController

public class TestController {

    private int var = 0;
    private static int staticVar = 0; // 定义一个静态变量
    ThreadLocal<Integer> tl = new ThreadLocal<>(); // 用ThreadLocal来封装变量

    @GetMapping(value = "/test_var")
    public String test() {
        tl.set(1);
        System.out.println("普通变量var:" + (++var));
        System.out.println("静态变量staticVar:" + (++staticVar));
        System.out.println("ThreadLocal变量tl:" + tl.get());
        System.out.println("====================================");
        return "普通变量var:" + var + "===ThreadLocal变量tl:" + tl.get();
    }
}
